package com.qidian.zl.paper.servlets;

import com.qidian.zl.paper.util.JsonTools;
import com.qidian.zl.paper.util.StResult;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet("/login")
public class LoginServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        StResult stResult=null;
        HttpSession session = request.getSession();
        if (session.getAttribute("adminId")!=null){
            stResult=StResult.ok();
        }else {
            stResult=StResult.fail();
        }
        response.setContentType("application/json;charset=utf-8");
        response.getWriter().write(JsonTools.obj2String(stResult));

        //response.sendRedirect("query");
    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}
